package com.caiyouxi.pay.service;

import com.caiyouxi.common.util.Log;
import com.caiyouxi.goods.model.GoodsInfo;
import com.caiyouxi.order.model.OrderBean;
import com.caiyouxi.pay.model.PaymentLogBean;
import org.nutz.lang.Lang;
import org.nutz.mvc.Mvcs;

import java.util.Date;

/**
 * 支付方式日志处理
 */
public class PayLogUtil {
    public static void insert(PayServiceImpl payService, String gateway_provider, String gateway_trade_no, String user_id, String gateway_buyer_id,
                              String payment_type, String direction, OrderBean order, GoodsInfo gInfo, int amount, String status, String trade_status,
                              String raw, String result_raw, String url, String error_code, String error_msg){
        PaymentLogBean bean = new PaymentLogBean();
        String ip = Lang.getIP(Mvcs.getReq());
        bean.setIp(ip);
        bean.setGateway_provider(gateway_provider);
        bean.setGateway_trade_no(gateway_trade_no);
        bean.setUser_id(user_id);
        bean.setGateway_buyer_id(gateway_buyer_id);
        bean.setPayment_type(payment_type);
        bean.setDirection(direction);
        bean.setGoods_id(gInfo.getId() == null ? "" : gInfo.getId().toString());
        bean.setGoods_title(gInfo.getTitle());
        bean.setGoods_detail(gInfo.getDetail());
        bean.setOrder_id(order.getId());
        bean.setAmount(amount);
        bean.setStatus(status);
        bean.setTrade_status(trade_status);
        bean.setRaw(raw);
        bean.setResult_raw(result_raw);
        bean.setUrl(url);
        bean.setCreate_time(new Date());
        bean.setError_code(error_code);
        bean.setError_msg(error_msg);
        Log.e("第三方支付请求或通知日志bean：" + bean.toString());
        Log.e("第三方支付请求或通知日志payService：" + payService.toString());
        PayLogThread logThread = new PayLogThread(bean,payService);
        logThread.start();

    }

    public static PaymentLogBean insertBean(String gateway_provider, String gateway_trade_no, String user_id, String gateway_buyer_id,
                              String payment_type, String direction, OrderBean order, int amount,String status, String trade_status,
                              String raw,String result_raw,String url,String error_code,String error_msg){
        PaymentLogBean bean = new PaymentLogBean();
        String ip = Lang.getIP(Mvcs.getReq());
        bean.setIp(ip);
        bean.setGateway_provider(gateway_provider);
        bean.setGateway_trade_no(gateway_trade_no);
        bean.setUser_id(user_id);
        bean.setGateway_buyer_id(gateway_buyer_id);
        bean.setPayment_type(payment_type);
        bean.setDirection(direction);

        bean.setOrder_id(order.getId());
        bean.setAmount(amount);
        bean.setStatus(status);
        bean.setTrade_status(trade_status);
        bean.setRaw(raw);
        bean.setResult_raw(result_raw);
        bean.setUrl(url);
        bean.setCreate_time(new Date());
        bean.setError_code(error_code);
        bean.setError_msg(error_msg);
        Log.e("第三方支付请求或通知日志bean：" + bean.toString());
        return bean;
    }

}
